/*
 * Place.java
 * Team qq 2011
 */
package com.google.code.timetrail.backend;

/**
 * The enumerated types for the places that are visited in the game
 * 
 * @author Steven Miller
 * @version 1.0
 */
public enum Place {
	// TODO replace numerals with static represenations
	/** The placeholder for being in transit */
	TRANSIT("In Transit", false, false),

	/** The starting Point */
	INDEPENDECE("Independence", false, true),

	/** The place called Kansas River, 102 time units in */
	KANSAS_RIVER("Kansas River", true, false),

	/** The place called Big Blue, 185 time units in, it has a river crossing */
	BIG_BLUE("Big Blue", true, false),

	/** The place called Fort Kearny, 304 time units in, it has a store */
	FORT_KEARNY("Fort Kearny", false, true),

	/** place called chimney rock, 554 time units in */
	CHIMNEY_ROCK("Chimney Rock", false, false),

	/** place called Fort Laramie, 640 time units in, it has a store */
	FORT_LARAMIE("Fort Laramie", false, true),

	/** place called Independence Rock, 830 time units in */
	INDEPENDENCE_ROCK("Independence Rock", false, false),

	/** place called South Pass, 932 time units in */
	SOUTH_PASS("South Pass", false, false),
	// we have the possibility for extra credit
	// to do a branching route here

	/** place called Fort Bridger, 1057 time units in, has a store */
	FORT_BRIDGER("Fort Bridger", false, true),

	/** place called Soda Springs, 1219 time units in */
	SODA_SPRINGS("Soda Springs", false, false),

	/** place called Fort Hall, 1276 time units in, it has a store */
	FORT_HALL("Fort Hall", false, true),

	/**
	 * place called Snake River Crossing, 1458 time units in, it has a river
	 * crossing
	 */
	SNAKE_RIVER_CROSSING("Snake River Crossing", true, false),

	/** place called Fort Boise, 1572 time units in, it has a store */
	FORT_BOISE("Fort Boise", false, true),

	/** place called Blue Mountains, 1734 time units in */
	BLUE_MOUNTAINS("Blue Mountains", false, false),

	/** place called Fort Walla Walla, 1789 time units in, it has a store */
	FORT_WALLA_WALLA("Fort Walla Walla", false, true),

	/** place called Dalles, 1909 time units in */
	DALLES("Dalles", false, false),

	/** The final land, Oregon */
	OREGON("Oregon", false, false);

	/** The value for the in transit enum */
	private static final int IN_TRANSIT_VALUE = -1;

	/** The value for the independence enum */
	private static final int INDEPENDENCE_VALUE = 0;

	/** The value for the kansas river enum */
	private static final int KANSAS_RIVER_VALUE = 102;

	/** The value for the big blue enum */
	private static final int BIG_BLUE_VALUE = 185;

	/** The value for the fort kearny enum */
	private static final int FORT_KEARNY_VALUE = 304;

	/** The value for the chimney rock enum */
	private static final int CHIMNEY_ROCK_VALUE = 554;

	/** The value for the fort laramite enum */
	private static final int FORT_LARAMIE_VALUE = 640;

	/** The value for the independence rock enum */
	private static final int INDEPENDENCE_ROCK_VALUE = 830;

	/** The value for the south pass enum */
	private static final int SOUTH_PASS_VALUE = 932;

	/** The value for the fort bridger enum */
	private static final int FORT_BRIDGER_VALUE = 1057;

	/** The value for the soda springs enum */
	private static final int SODA_SPRINGS_VALUE = 1219;

	/** The value for the fort hall enum */
	private static final int FORT_HALL_VALUE = 1276;

	/** The value for the snake river crossing enum */
	private static final int SNAKE_RIVER_CROSSING_VALUE = 1458;

	/** The value for the fort boise enum */
	private static final int FORT_BOISE_VALUE = 1572;

	/** The value for the blue mountain enum */
	private static final int BLUE_MOUNTAINS_VALUE = 1734;

	/** The value for the fort walla walla enum */
	private static final int FORT_WALLA_WALLA_VALUE = 1789;

	/** The value for the dalles enum */
	private static final int DALLES_VALUE = 1909;

	/** The value for the oregon enum */
	private static final int OREGON_VALUE = 1910;

	/** The time-distance that this place occurs in */
	private final int location;

	/** The name of the place */
	private final String name;

	/** if there is a river crossing at that place */
	private final boolean riverCross;

	/** if there is a working store at that place */
	private final boolean storeOpen;

	/**
	 * Sets up the Place types
	 * 
	 * @param name
	 *            the name of the place
	 * @param riverCross
	 *            if the place has a river to cross
	 * @param storeOpen
	 *            if there is an open store at that place
	 */
	private Place(String name, boolean riverCross, boolean storeOpen) {
		this.name = name;
		this.riverCross = riverCross;
		this.storeOpen = storeOpen;

		if (this.name.equals("In Transit")) {
			this.location = IN_TRANSIT_VALUE;
		} else if (this.name.equals("Independence")) {
			this.location = INDEPENDENCE_VALUE;
		} else if (this.name.equals("Kansas River")) {
			this.location = KANSAS_RIVER_VALUE;
		} else if (this.name.equals("Big Blue")) {
			this.location = BIG_BLUE_VALUE;
		} else if (this.name.equals("Fort Kearny")) {
			this.location = FORT_KEARNY_VALUE;
		} else if (this.name.equals("Chimney Rock")) {
			this.location = CHIMNEY_ROCK_VALUE;
		} else if (this.name.equals("Fort Laramie")) {
			this.location = FORT_LARAMIE_VALUE;
		} else if (this.name.equals("Independence Rock")) {
			this.location = INDEPENDENCE_ROCK_VALUE;
		} else if (this.name.equals("South Pass")) {
			this.location = SOUTH_PASS_VALUE;
		} else if (this.name.equals("Fort Bridger")) {
			this.location = FORT_BRIDGER_VALUE;
		} else if (this.name.equals("Soda Springs")) {
			this.location = SODA_SPRINGS_VALUE;
		} else if (this.name.equals("Fort Hall")) {
			this.location = FORT_HALL_VALUE;
		} else if (this.name.equals("Snake River Crossing")) {
			this.location = SNAKE_RIVER_CROSSING_VALUE;
		} else if (this.name.equals("Fort Boise")) {
			this.location = FORT_BOISE_VALUE;
		} else if (this.name.equals("Blue Mountains")) {
			this.location = BLUE_MOUNTAINS_VALUE;
		} else if (this.name.equals("Fort Walla Walla")) {
			this.location = FORT_WALLA_WALLA_VALUE;
		} else if (this.name.equals("Dalles")) {
			this.location = DALLES_VALUE;
		} else if (this.name.equals("Oregon")) {
			this.location = OREGON_VALUE;
		} else {
			this.location = IN_TRANSIT_VALUE;
		}
	}

	/**
	 * Will find the next place to go to in time given your last location
	 * visited
	 * 
	 * @return at the very least will return the last place you visited
	 */
	public Place findNextPlace() {
		Place nextPlace = this;
		int nextDistance = Integer.MAX_VALUE;

		for (Place p : Place.values()) {
			if (p.getLocation() > this.getLocation()
					&& p.getLocation() < nextDistance) {
				nextPlace = p;
				nextDistance = p.getLocation();
			}
		}

		return nextPlace;
	}

	/**
	 * 
	 * 
	 * @return the time location of the Place
	 */
	public int getLocation() {
		return location;
	}

	/**
	 * 
	 * 
	 * @return the string representation of the place
	 */
	public String getName() {
		return name;
	}

	/**
	 * 
	 * 
	 * @return true if the place is a river crossing
	 */
	public boolean hasRiverCross() {
		return riverCross;
	}

	/**
	 * 
	 * 
	 * @return true if the place has a store
	 */
	public boolean hasStoreOpen() {
		return storeOpen;
	}
}
